{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <form class="layui-form" onsubmit="return false;" id="layuiForm">
                        <div class="layui-form layui-form-item">
                            <div class="layui-input-inline layui-form">
                                <select name="role" lay-search="">
                                    <option  value="">不限状态</option>
                                    <option  value="1">未使用</option>
                                    <option  value="2">已使用</option>
                                </select>
                            </div>
                            <div class="layui-input-inline layui-form">
                                <select name="area" lay-search="">
                                    <option value="">请选择地区</option>
                                    {if !empty($data)}
                                    {foreach name="data" item="vo"}
                                    <option value="{$vo.district_id}" >{$vo.district}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="卡号"/>
                            </div>
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" class="layui-input search" name="number" placeholder="积分数" oninput="value=value.replace(/[^\d]/g,'')"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('cardAdd')}');">
                            <i class="fa fa-plus"></i> 添加充值卡
                        </button>
                        <button class="btn btn-info layuiBtn m-l-xs" type="button" data-type="excelAll">
                            导出EXCEL
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.user_image}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <!--角色模板-->
                    <script type="text/html" id="titleTpl">
                        {{# if(d.card_status == 1){ }}
                        未使用
                        {{# }else{ }}
                        已使用
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('cardEdit')}?id={{d.card_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil"></i></a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.card_id}}','{:url('cardDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o"></i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Card/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: 10
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'card_number', width: '', title: '卡号', align: 'center'}
                , {field: 'card_unencrypted', width: '', title: '密码', align: 'center'}
                , {field: 'card_sum', width: '', title: '额度', align: 'center'}
                , {field: 'card_status', width: '', title: '状态', align: 'center', templet: '#titleTpl'}
                , {field: 'card_add_time', width: '', title: '添加时间', align: 'center'}
                , {field: 'district', width: '', title: '地区代理', align: 'center'}
                , {field: 'card_edit_time', width: '', title: '编辑时间', align: 'center'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]],
            done: function (res, curr, count) {
                $('.img-circle').viewer();
            }
        });

        //批量操作
        var $ = layui.$, active = {
            excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$('#layuiForm').serialize(),"{:url('excelAdmin')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['fund_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>